package br.com.mworks.controller;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.ufc.mworks.model.Tarefa;

import com.example.mworks.InfoTarefaActivity;
import com.example.mworks.R;

public class CustomAdapterTFeitas extends BaseAdapter {

	private ArrayList<Tarefa> listaTarefas;
	Context c;

	public CustomAdapterTFeitas(ArrayList<Tarefa> listaTaref, Context context) {
		listaTarefas = listaTaref;
		c = context;
	}

	@Override
	public int getCount() {
		return listaTarefas.size();
	}

	@Override
	public Object getItem(int position) {
		return listaTarefas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.item_listtfeitas, null);
		}

		final TextView nomeTarefa = (TextView) v
				.findViewById(R.id.nameTarefaFeita);
		final TextView dataTarefa = (TextView) v
				.findViewById(R.id.dataTarefaFeita);

		Tarefa tarefa = listaTarefas.get(position);

		nomeTarefa.setText(tarefa.getNome());
		dataTarefa.setText(tarefa.getData().toString());

		v.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				Intent i = new Intent(c, InfoTarefaActivity.class);
				i.putExtra("nomeTarefa", nomeTarefa.getText());
				i.putExtra("dataTarefa", dataTarefa.getText());
				c.startActivity(i);
			}
		});

		return v;
	}
}